"""
    Author:
    Date: 2018-10-26

    微信管理后台-主播审核页面
"""

from django.shortcuts import render

from entities import user_mgr
from entities import vchat_api_mgr
from entities.consts import *
from utils import ajax
from utils.log import Log

from .. import helpers
from .. helpers import gma_login_required





# @gma_login_required
# def detail(request, uid):
#     """ 主播审核详情 """
#     context = helpers.build_context(request)
#     context['username'] = request.user.username
#     context['user'] = user_mgr.get_broadcaster_detail(uid)
#     return render(request, 'gma/auth/waiting_auth_user_detail.html', context)


# ------------------------------------------------------------------------------
# API
# ------------------------------------------------------------------------------

@gma_login_required
def api_agree(request, uid):
    """ 同意主播审核 """
    Log.info(f'Agree broadcaster auth: uid={uid}, admin={request.user.username}')
    uid = int(uid)

    # 注意: 只有主播审核通过，才会计算主播的在线时长，因此此处不能调用设置勿扰模式的接口
    # 这个逻辑交由ApiServer来处理
    vchat_api_mgr.agree_broadcaster_auth(uid)

    success = True
    return ajax.response(success, error='授权认证失败!')


@gma_login_required
def api_reject(request, uid):
    """ 拒绝主播审核 """
    Log.info(f'Reject broadcaster auth: uid={uid}, admin={request.user.username}')
    uid = int(uid)

    # 注意：拒绝主播后，如果主播当前处于在线状态，则将主播设置为勿扰模式，并对主播的在线时长进行一次结算
    # 这个逻辑交由ApiServer来处理
    vchat_api_mgr.reject_broadcaster_auth(uid)

    success = True
    return ajax.response(success, error='取消授权失败!')


if __name__ == '__main__':
    print('ok')
